package com.bootdo.program.film.controller;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.bootdo.program.film.domain.FilmCategoryDO;
import com.bootdo.program.film.service.FilmCategoryService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;

/**
 * 影视分类
 *
 * @author guoyunfei
 * @email 2549789059@qq.com
 * @date 2023-09-02 17:53:25
 */

@Controller
@RequestMapping("/film/filmCategory")
public class FilmCategoryController {
	@Autowired
	private FilmCategoryService filmCategoryService;

	@GetMapping()
	@RequiresPermissions("film:filmCategory:filmCategory")
	String FilmCategory(){
	    return "film/filmCategory/filmCategory";
	}

	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("film:filmCategory:filmCategory")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<FilmCategoryDO> filmCategoryList = filmCategoryService.list(query);
		int total = filmCategoryService.count(query);
		PageUtils pageUtils = new PageUtils(filmCategoryList, total);
		return pageUtils;
	}

	@GetMapping("/add")
	@RequiresPermissions("film:filmCategory:add")
	String add(){
	    return "film/filmCategory/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("film:filmCategory:edit")
	String edit(@PathVariable("id") Long id,Model model){
		FilmCategoryDO filmCategory = filmCategoryService.get(id);
		model.addAttribute("filmCategory", filmCategory);
	    return "film/filmCategory/edit";
	}

	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("film:filmCategory:add")
	public R save( FilmCategoryDO filmCategory){
		filmCategory.setDelFlag(0);
		filmCategory.setCreateTime(new Date());
		if(filmCategoryService.save(filmCategory)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("film:filmCategory:edit")
	public R update( FilmCategoryDO filmCategory){
		filmCategory.setUpdateTime(new Date());
		filmCategoryService.update(filmCategory);
		return R.ok();
	}

	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("film:filmCategory:remove")
	public R remove( Long id){
		FilmCategoryDO filmCategoryDO = filmCategoryService.get(id);
		filmCategoryDO.setDelFlag(1);
		if(filmCategoryService.update(filmCategoryDO)>0){
		return R.ok();
		}
		return R.error();
	}


}
